package com.li.controller;

import com.li.common.config.Result;
import com.li.mapper.CardMapper;

import com.li.pojo.Card;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/card")
public class CardController {
  @Autowired
  CardMapper CardMapper;
  
  //获取公告列表
  @GetMapping
  public Result<?> getStudents(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer rows){
    Map<String, Object> ret = new HashMap<String, Object>();
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put("offset", ((page - 1) * rows));
    queryMap.put("pageSize", rows);
    ret.put("rows", CardMapper.findCardList(queryMap));
    ret.put("total", CardMapper.getCardTotal(queryMap));
    return Result.success(ret);
  }
  

  @GetMapping("/no")
  public Result<?> getCardsno(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer rows){
    Map<String, Object> ret = new HashMap<String, Object>();
    Map<String, Object> queryMap = new HashMap<String, Object>();
    queryMap.put("offset", ((page - 1) * rows));
    queryMap.put("pageSize", rows);
    ret.put("rows", CardMapper.findCardListno(queryMap));
    ret.put("total", CardMapper.getCardTotalno(queryMap));
    return Result.success(ret);
  }
  
  /**
   * 更新
   *
   * @param
   * @return
   */
  @PutMapping
  public Result<?> update(@RequestBody Card card) {
    card.setCtime(new Date());
    card.setSure(1);
    System.out.println(card);
    CardMapper.updateById(card);
    return Result.success();
  }
  
  
}
